package org.rcy.ruicingmarket.file.utils;



import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

import java.io.OutputStream;
import java.util.List;
import java.util.Map;

/**
 * Author ruicywu
 */
public class PdfUtils {
    /**
     * 用于导出pdf报表
     * @param data
     * @param ops
     * @throws JRException
     */
    public static void exportPdf(Map data, OutputStream ops) throws JRException {
        String jrxmlPath = "D:\\WKQproject\\java\\health_parent\\health_backend\\src\\main\\webapp\\WEB-INF\\out\\health_business3.jrxml";
        String jasperPath = "D:\\WKQproject\\java\\health_parent\\health_backend\\src\\main\\webapp\\WEB-INF\\out\\health_business3.jasper";

        //编译模板
        JasperCompileManager.compileReportToFile(jrxmlPath,jasperPath);
        List<Map> hotSetmeal= (List<Map>) data.get("hotSetmeal");
        //填充数据---使用JavaBean数据源方式填充
        JasperPrint jasperPrint =
                JasperFillManager.fillReport(jasperPath,
                        data,
                        new JRBeanCollectionDataSource(hotSetmeal));
        //输出流
        JasperExportManager.exportReportToPdfStream(jasperPrint,ops);
    }

}
